//
//  OCSSStorageCell.swift
//  OCSSStoreSwift
//
//  Created by MacMiniKangChe on 2018/10/15.
//  Copyright © 2018年 MacMiniKangChe. All rights reserved.
//

import UIKit
protocol OCSSStorageCellDelegate {
    func buttonDidClicked(button:UIButton, categoryName: String) -> Void;
}
class OCSSStorageCell: UITableViewCell {
    @IBOutlet weak var icon: UIImageView!

    var delegate:OCSSStorageCellDelegate?;
    
    
    @IBOutlet weak var titleLab: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    func setCellWithDict(dict:NSDictionary) -> Void {
        icon.image = UIImage.init(named: dict["icon"] as! String);
        titleLab.text = dict["name"] as? String;
        let titles = dict["titles"] as! NSArray;
        
        for i in 0...7 {
            let btn:UIButton = self.viewWithTag(10+i) as! UIButton;
            if i>=titles.count{
                btn.isHidden = true;
            }else{
                btn.isHidden = false;
                btn.setTitle(titles[i] as? String, for: UIControlState.normal);
            }
        }

    }
    @IBAction func buttonEvent(_ sender: UIButton) {
        delegate?.buttonDidClicked(button: sender, categoryName: titleLab.text!);
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
